(bug 10732 and others) Further fixes to protect chaining JavaScript; introduce addCli...
authorRob Church <robchurch@users.mediawiki.org>
Sun, 29 Jul 2007 14:32:26 +0000 (14:32 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sun, 29 Jul 2007 14:32:26 +0000 (14:32 +0000)
includes/DefaultSettings.php
skins/common/protect.js
skins/common/wikibits.js

index f6b9123..1996376 100644 (file)
@@ -1195,7 +1195,7 @@ $wgCacheEpoch = '20030516000000';
  * to ensure that client-side caches don't keep obsolete copies of global
  * styles.
  */
-$wgStyleVersion = '91';
+$wgStyleVersion = '92';
 
 
 # Server-side caching:
index 7691eba..a2ebcd7 100644 (file)
@@ -1,44 +1,37 @@
-function protectInitialize(tableId, labelText) {
-       if (document.createTextNode) {
-               var box = document.getElementById(tableId);
-               if (!box)
-                       return false;
-
-               var tbody = box.getElementsByTagName('tbody')[0];
-               var row = document.createElement('tr');
-               tbody.appendChild(row);
-
-               row.appendChild(document.createElement('td'));
-               var col2 = document.createElement('td');
-               row.appendChild(col2);
-
-               var check = document.createElement('input');
-               check.id = "mwProtectUnchained";
-               check.type = "checkbox";
-               check.addEventListener( 'click', protectChainUpdate, false );
-               col2.appendChild(check);
-
-               var space = document.createTextNode(" ");
-               col2.appendChild(space);
-
-               var label = document.createElement('label');
-               label.setAttribute("for", "mwProtectUnchained");
-               label.appendChild(document.createTextNode(labelText));
-               col2.appendChild(label);
-
-               if (protectAllMatch()) {
-                       check.checked = false;
-                       protectEnable(false);
-               } else {
-                       check.checked = true;
-                       protectEnable(true);
-               }
+function protectInitialize( tableId, labelText ) {
+       if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) )
+               return false;
                
-               allowCascade();
-
-               return true;
-       }
-       return false;
+       var box = document.getElementById( tableId );
+       if( !box )
+               return false;
+               
+       var tbody = box.getElementsByTagName( 'tbody' )[0];
+       var row = document.createElement( 'tr' );
+       tbody.appendChild( row );
+       
+       row.appendChild( document.createElement( 'td' ) );
+       var col = document.createElement( 'td' );
+       row.appendChild( col );
+       
+       var check = document.createElement( 'input' );
+       check.id = 'mwProtectUnchained';
+       check.type = 'checkbox';
+       col.appendChild( check );
+       addClickHandler( check, protectChainUpdate );
+
+       col.appendChild( document.createTextNode( ' ' ) );
+       var label = document.createElement( 'label' );
+       label.setAttribute( 'for', 'mwProtectUnchained' );
+       label.appendChild( document.createTextNode( labelText ) );
+       col.appendChild( label );
+
+       check.checked = !protectAllMatch();
+       protectEnable( check.checked );
+       
+       allowCascade();
+       
+       return true;
 }
 
 function allowCascade() {
@@ -90,12 +83,10 @@ function protectAllMatch() {
 }
 
 function protectUnchained() {
-       var unchain = document.getElementById("mwProtectUnchained");
-       if (!unchain) {
-               alert("This shouldn't happen");
-               return false;
-       }
-       return unchain.checked;
+       var unchain = document.getElementById( 'mwProtectUnchained' );
+       return unchain
+               ? unchain.checked
+               : true; // No control, so we need to let the user set both levels
 }
 
 function protectChain() {
index af3ffc6..0aef60a 100644 (file)
@@ -1302,8 +1302,24 @@ function runOnloadHook() {
        }
 }
 
+/**
+ * Add a click event handler to an element
+ *
+ * We use addEventListener() where available, otherwise
+ * we use a workaround to avoid breaking the chain
+ *
+ * @param Element element Element to add handler to
+ * @param callable handler Event handler callback
+ */
+function addClickHandler( element, handler ) {
+       if( window.addEventListener ) {
+               element.addEventListener( 'click', handler, false );
+       } else if( window.attachEvent ) {
+               element.attachEvent( 'onclick', handler );
+       }
+}
+
 //note: all skins should call runOnloadHook() at the end of html output,
 //      so the below should be redundant. It's there just in case.
 hookEvent("load", runOnloadHook);
-
-hookEvent("load", mwSetupToolbar);
+hookEvent("load", mwSetupToolbar);
\ No newline at end of file